package com.jnu.hc.jnuhcusercms.service;

import com.jnu.hc.jnuhcusercms.domain.Checkitem;
import com.jnu.hc.jnuhcusercms.domain.Setmeal;
import com.jnu.hc.jnuhcusercms.domain.Setmealdetailed;
import com.jnu.hc.jnuhcusercms.dto.ResponseObject;
import com.jnu.hc.jnuhcusercms.mapper.CheckitemMapper;
import com.jnu.hc.jnuhcusercms.mapper.SetmealMapper;
import com.jnu.hc.jnuhcusercms.mapper.SetmealdetailedMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.ArrayList;
import java.util.List;

@Service
public class SetmealServiceImpl implements SetmealService {
    @Autowired
    SetmealMapper setmealMapper;
    @Autowired
    SetmealdetailedMapper setmealdetailedMapper;
    @Autowired
    CheckitemMapper checkitemMapper;

    @Override
    public ResponseObject setmealList(Integer sex){
        List<Setmeal> setmealList = setmealMapper.selectBySex(sex);
        for(int i=0;i<setmealList.size();i++){
            Setmeal setmeal = setmealList.get(i);
            List<Setmealdetailed> setmealdetailedList =setmealdetailedMapper.selectBySetmealId(setmeal.getSmId());
            List<Checkitem> checkitemList=new ArrayList<>();
            for(Setmealdetailed sd:setmealdetailedList){
                Integer ciId=sd.getCiId();
                Checkitem checkitem=checkitemMapper.selectByPrimaryKey(ciId);
                checkitemList.add(checkitem);
            }
            setmeal.setCheckitemList(checkitemList);
        }
        return new ResponseObject(ResponseObject.SUCCESS_STATUS,ResponseObject.SUCCESS_DESC,setmealList);
    }
}
